﻿package app.view.components.guiDima.sky 
{
	import app.view.events.KeyboardEventD;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	/**
	 * Базовый класс для облака
	 * @author dmitryi koruagin, icq:585466579, dmitryikoruagin@mail.ru, skype: ok_ru1
	 */
	public class SkyDBase extends Sprite
	{
		// app.view.components.guiDima.sky.SkyDBase
		
		//	public
		public var txt:TextField;
		
		private var _id:int;
		//	private
		private var _currentText:String;
		//	const
		
		
		//	CONSTRUCTOR
		public function SkyDBase() 
		{
			init();
		}
		
		//	METHODS
		//	private
		private function init():void
		{
			txt.wordWrap = true;
			txt.multiline = true;
			txt.selectable = false;
			
			addEventListener(MouseEvent.CLICK, onClick);
		}
		
		
		//	public
		public function destroy():void
		{
			removeEventListener(MouseEvent.CLICK, onClick);
			
		}
		
		public function updateDisplayList(sw:Number,sh:Number):void
		{
			
		}
		
		public function get currentText():String { return _currentText; }
		
		public function set currentText(value:String):void 
		{
			_currentText = value;
			
			if (_currentText!='') 
			{
				txt.htmlText = '"'+String(_currentText).substr(1,40)+'..."';
			}
		}
		
		public function get id():int { return _id; }
		
		public function set id(value:int):void 
		{
			_id = value;
		}
		//	----------------------------------------------------------------------------------
		
		//	GETTERS/SETTERS
		
		//	----------------------------------------------------------------------------------
		
		//	HANDLERS
		private function onClick(e:MouseEvent):void 
		{
			if (_currentText!='') 
			{
				var ev:KeyboardEventD = new KeyboardEventD(KeyboardEventD.ON_CLICK_SKY_MESSAGE);
				ev.id = _id;
				ev.str = _currentText;
				dispatchEvent(ev);
			}
		}
		
	}

}